package com.cskaoyan.shopping.service.impl;

import com.cskaoyan.shopping.converter.ContentConverter;
import com.cskaoyan.shopping.dal.entitys.PanelContent;
import com.cskaoyan.shopping.dal.persistence.PanelContentMapper;
import com.cskaoyan.shopping.dto.PanelContentDto;
import com.cskaoyan.shopping.service.IContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

import static com.cskaoyan.shopping.constants.GlobalConstants.HEADER_PANEL_ID;
import static com.cskaoyan.shopping.constants.GlobalConstants.PANEL_CONTENT_PANEL_ID;

/**
 * @author xD
 * @since 2023/01/10 22:29
 */
@Service
public class IContentServiceImpl implements IContentService {
    @Autowired
    private PanelContentMapper panelContentMapper;

    @Autowired
    private ContentConverter contentConverter;

    @Override
    public List<PanelContentDto> queryNavList() {
        Example example = new Example(PanelContent.class, true);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo(PANEL_CONTENT_PANEL_ID, HEADER_PANEL_ID);
        List<PanelContent> panelContents = panelContentMapper.selectByExample(example);
        return contentConverter.panelContents2Dto(panelContents);
    }
}
